﻿import "babel-polyfill";
import Vue from 'vue';
//import qs from 'qs';

Vue.config.productionTip = true;

//vuex
import store from './vuex/store' // 引入store


//全局变量
import global from '../config/global.js'
Vue.prototype.GLOBAL = global;

//element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//import './lib/elementui/theme/index.css';
//Vue.use(ElementUI, { size: 'mini' });
Vue.use(ElementUI);


//$http
import http from './lib/js/vue.http.js';
//注入
http.init({
    store,
    global,
    router
});
Vue.prototype.$http = http;


//自定义组件
import EgLayout from './components/EgLayout';
Vue.component('eg-layout', EgLayout)

//自定义js方法
import util from './lib/js/vue.util.js';
util.init({
    store: store
});
Vue.prototype.$util = util;

//多语言
import Localization from './lib/js/vue.localization.js';
Vue.prototype.$sl = Localization.l;
Vue.prototype.$l = (s, arr) => {
    return Localization.l(s, arr);
};


//路由
import VueRouter from 'vue-router'
import routers from './routers'
Vue.use(VueRouter);
const router = new VueRouter({
    //mode: 'hash',
    mode: 'history',
    routes: routers
})
router.beforeEach(function (to, from, next) {
    if (to.name && !util.checkAuth(to.name)) {
        next(global.BASE_URL + '/NoAuthority?from=' + escape(from.fullPath));
    } else {
        var _token = store.getters.getToken;
        if (_token) {
            next();
        } else {
            next(global.BASE_URL + '/Login');
        }
    }
});

//路由跳转
Vue.prototype.$goRoute = function (path, query) {
    if (path.indexOf('/') === 0) {
        path = global.BASE_URL + path;
    }
    if (query) {
        this.$router.push({ path: path, query: query });
    } else {
        this.$router.push(path);
    }
}

//自定义css样式
import './lib/css/index.css';

//自定义图标
import './lib/eg-icon/iconfont.base.css';
import './lib/eg-icon/iconfont.css';

//APP
import App from './App.vue';
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app');